/*
    Copyright (C) <2007-2013> Kay Diefenthal

    SimpleRadio is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SimpleRadio is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with SimpleRadio.  If not, see <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using Microsoft.MediaCenter.Hosting;
using SimpleRadio.Logging;
using SimpleRadio.Properties;

namespace SimpleRadio
{
    /// <summary>
    /// <see cref="MyAddIn"/> Class.
    /// </summary>
    public class MyAddIn : IAddInModule, IAddInEntryPoint
    {
        #region Private Fields

        private DefaultModel _model;

        #endregion

        #region Public Methods

        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="appInfo">appInfo <seealso cref="System.Collections.Generic.Dictionary"/></param>
        /// <param name="entryPointInfo">entryPointInfo <seealso cref="System.Collections.Generic.Dictionary"/></param>
        public void Initialize(Dictionary<string, object> appInfo, Dictionary<string, object> entryPointInfo)
        {
            Logger.SetLogFilePath("AddIn.log", Settings.Default.LogLevel);
            Logger.Info(string.Format("{0} - {1}", "Initialize", "SimpleRadio"));
        }

        /// <summary>
        /// Uninitialize
        /// </summary>
        public void Uninitialize()
        {
            if (_model != null)
            {
                Settings.Default.Mode = _model.ModeIndex;
                Settings.Default.Save();
                Logger.Info(string.Format("{0} - {1}", "Uninitialize", "SimpleRadio"));
            }
        }
        /// <summary>
        /// Launch
        /// </summary>
        /// <param name="host">host <seealso cref="Microsoft.MediaCenter.Hosting.AddInHost"/></param>
        public void Launch(AddInHost host)
        {
            if (host != null && host.ApplicationContext != null)
            {
                host.ApplicationContext.SingleInstance = true;
            }
            _model = new DefaultModel(new HistoryOrientedPageSession(), host) { ModeIndex = Settings.Default.Mode };
            _model.GoToDefaultView();
        }
        #endregion
    }
}